package com.china08.yxyapi.api.manage.tec.teaching.homework.worklist.workcorrect1;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.homework.HomeworkTaskReportQues;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskReportQuesRepository;

/**
 * 获取学生作业试题列表
 */
@CrossOrigin
@RestController
public class Workcorrect1FindStuTaskQuesLstController {

    @Autowired
    HomeworkTaskReportQuesRepository homeworkTaskReportQuesRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/homework/worklist/workcorrect1/stu/task/ques/find", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(//
            HttpServletRequest request, //
            HttpServletResponse response, //
            @RequestParam String taskId, //
            @RequestParam String studentId, //
            RespModel respModel) throws ParseException {

        // 获取学生答题记录
        List<HomeworkTaskReportQues> homeworkTaskReportQuesLst = homeworkTaskReportQuesRepository
                .findByStudentIdAndTaskIdOrderByOrder(studentId, taskId);

        // return
        List<RespModel> models = new ArrayList<RespModel>();
        for (HomeworkTaskReportQues homeworkTaskReportQues : homeworkTaskReportQuesLst) {
            // 不输出主观题
            if (homeworkTaskReportQues.getQuestionType().equals("0")
                    || homeworkTaskReportQues.getQuestionType().equals("1")) {
                continue;
            }
            RespModel model = new RespModel();
            model.homeworkTaskReportQuesId = homeworkTaskReportQues.getId();
            model.quesId = homeworkTaskReportQues.getQuesId();
            model.questionType = homeworkTaskReportQues.getQuestionType();
            model.mark = homeworkTaskReportQues.getMark();
            model.order = homeworkTaskReportQues.getOrder();
            models.add(model);
        }
        return models;
    }

    /** 响应 **/
    protected static class RespModel extends YxyApiRespModel {
        // HomeworkTaskReportQues 主键Id
        public String homeworkTaskReportQuesId;
        // 试题
        public String quesId;
        // 试题类型，使用题库中的的类型 （0--单选，1--多选，2--通知，3--填空，4--问答,5--阅读）</br>
        public String questionType;
        // 评分 mark
        public Integer mark;
        // 试题序号
        public Integer order;

    }

}
